package liumengbaio.lolzhangyoubao.Activity.Activity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import liumengbaio.lolzhangyoubao.R;

/**
 * Created by lanouhn on 16/9/13.
 */
public class InfoPushActivity extends AppCompatActivity {
    private boolean flag = true;
    private SharedPreferences sp;
    private SharedPreferences.Editor editor;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.info_push_activity);
        sp = getSharedPreferences("infoPush", MODE_PRIVATE);
        editor = sp.edit();
        flag = sp.getBoolean("infoPush", true);
        if (flag) {
            findViewById(R.id.btn_info_push).setBackgroundResource(R.mipmap.user_switch_on);
            flag = false;
        } else {
            findViewById(R.id.btn_info_push).setBackgroundResource(R.mipmap.user_switch_on);
            flag = true;
        }
        findViewById(R.id.btn_info_push).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (flag) {
                    findViewById(R.id.btn_info_push).setBackgroundResource(R.mipmap.user_switch_on);
                    flag = false;
                    editor.putBoolean("flag", flag);
                    editor.commit();
                } else {
                    findViewById(R.id.btn_info_push).setBackgroundResource(R.mipmap.user_switch_on);
                    flag = true;
                    editor.putBoolean("flag", flag);
                    editor.commit();
                }
            }
        });
        findViewById(R.id.edit_head_left_title).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
